#!/usr/bin/env bash

# https://npmmirror.com/
# curl -fsSL http://dev8.cn:8000/static/ops/node-js.sh | bash
which "node" > /dev/null
if [ $? -eq 0 ]
then
    echo "node已安装"
else
    echo "安装node..."
    wget https://registry.npmmirror.com/-/binary/node/v14.19.1/node-v14.19.1-linux-x64.tar.xz -P /opt/ -N

    cd /opt
    xz -d `ls /opt/node-v14.19.*.tar.xz`
    tar -xf `ls /opt/node-v14.19.*.tar`  -C /opt
    path2=`ls -F /opt | grep '/$'| grep node-v14.19 | sed 's/.$//'`

    echo -e "\n# NODE_HOME \n \
export NODE_HOME=/opt/$path2 \n \
export PATH=\$NODE_HOME/bin:\$PATH " | sudo tee -a /etc/profile
    source /etc/profile
fi